package cn.bytepulse.web.video.service.impl;

import cn.bytepulse.utils.MinioUtils;
import cn.bytepulse.web.admin.entity.SysAssets;
import cn.bytepulse.web.admin.mapper.SysAssetsMapper;
import cn.bytepulse.web.video.service.PlayerService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author jiejiebiezheyang
 * @since 2025-03-17 19:00
 */
@Service
@Transactional
@RequiredArgsConstructor
public class PlayerServiceImpl implements PlayerService {

    private final MinioUtils minioUtils;

    private final SysAssetsMapper sysAssetsMapper;

    /**
     * HLS文件获取
     *
     * @param partId   分集id
     * @param filename 文件名
     */
    @Override
    public ResponseEntity<InputStreamResource> hls(String partId, String filename) throws Exception {
        QueryWrapper<SysAssets> wrapper = new QueryWrapper<>();
        wrapper.eq("relation_type", "video_part");
        wrapper.eq("relation_number", partId);
        SysAssets sysAssets = sysAssetsMapper.selectOne(wrapper);
        return minioUtils.returnFile(sysAssets.getObjectKey() + filename, filename);
    }
}
